package leetcode.editor.cn;

import java.util.*;

public class ID2981FindLongestSpecialSubstringThatOccursThriceI{
	public static void main(String[] args) {
		Solution solution = new ID2981FindLongestSpecialSubstringThatOccursThriceI().new Solution();
		StringBuilder sb = new StringBuilder();
		
		//执行测试
		int ans = solution.maximumLength(new String("aaaa"));
		System.out.println(ans);
	}
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
	public int maximumLength(String s) {
		Map<String,Integer>map = new HashMap<>();
		int n = s.length();
		for(int i=0;i<n;i++){
			int flag = 0;
			for(int j=i+1;j<=n;j++){
				String ss = s.substring(i,j);

				for(int k=0;k<ss.length()-1;k++){
					if(ss.charAt(k)!=ss.charAt(k+1)){
						flag = 1;
						break;
					}
				}
				if(flag == 1){
					break;
				}
				map.put(ss,map.getOrDefault(ss,0)+1);
			}
		}
		int res = -1;
		for(String key:map.keySet()){
			if(map.get(key)>=3){
				res = Math.max(res,key.length());
			}
		}
		return res;
	}
}


//leetcode submit region end(Prohibit modification and deletion)

}
